//
//  GUID.m
//  MobilCommunity
//
//  Created by easystudio on 7/4/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "GUID.h"
#import <commoncrypto/CommonDigest.h>

@implementation GUID
+(NSString*) getGUIDString
{
  
    UIDevice* myDevice = [UIDevice currentDevice];
    NSString* deviceID = [myDevice uniqueIdentifier];
    
    //UUID是Universally Unique Identifier 通用唯一标识码
//    CFUUIDRef puuid = CFUUIDCreate( nil );  
//    CFStringRef uuidString = CFUUIDCreateString( nil, puuid );  
//    NSString * deviceID = (NSString *)CFStringCreateCopy( NULL, uuidString);  
//    CFRelease(puuid);  
//    CFRelease(uuidString);  

    NSDate* currentDate = [NSDate date];
        
    NSString* source = [NSString stringWithFormat:@"%@%@%ld%ld%ld", deviceID, [currentDate description],random(), random(), random()];
    
//    NSLog(@"%@", source);
    const char *cStr = [source UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(cStr, strlen(cStr), result);
    NSString* retStr = [NSString stringWithFormat:@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",result[0],result[1],result[2],result[3],result[4],result[5],result[6],result[7],result[8],result[9],result[10],result[11],result[12],result[13],result[14],result[15]];
//    NSLog(@"%@", retStr);
    return retStr;
}

@end
